<style>
#load_admin_form
{
    position:absolute;
    left:50%; 
    top:50%;
	z-index:1000;
}
</style>
<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<script src="../js/jquery-1.6.2.min.js"></script>
	<script src="../js/load.js"></script>
	<script src="../js/url.js"></script>
	<link rel="stylesheet" href="../css/style.css" />
</head>
<script>
$(window).load(function(){
	if(typeof sessionStorage["adminemail"]!='undefined'){
		$.ajax({
			type		:	'GET',
			url			:  	webServiceUrl+'admin',
			dataType	: 	"json",
			success: function(data){
				if(data.value==1){
				var obj = eval("(" + data.data + ")");
					$.each(obj, function (index,Object) {
						$('#hideenWinId').val(Object.win_id);
						$('#winMessage').html(Object.win_message);
						$('#winMessageArabic').html(Object.win_message_arabic);
						$('#win_message').val(Object.win_message);
						$('#win_message_arabic').val(Object.win_message_arabic);
						$('#winLogo').html('<img src="'+webImageUrl+Object.win_logo+'" height="42" width="42">');
						$('#imglogo').html('<img src="'+webImageUrl+Object.win_logo+'" height="42" width="42">');
						$('#reglogo').html('<img src="'+webImageUrl+Object.reg_image+'" height="42" width="42">');
						$('#RegImage').html('<img src="'+webImageUrl+Object.reg_image+'" height="42" width="42">');
						$('#nooffailure_attemts').html(Object.numberof_failure_attemts);
						$('#numberof_failure_attemts').val(Object.numberof_failure_attemts);
						$('#noofchances_perday').html(Object.numberof_chance_per_day);
						$('#numberof_chance_per_day').val(Object.numberof_chance_per_day);
						$('#noofsuccess_perday').html(Object.numberof_success_per_day);
						$('#numberof_success_per_day').val(Object.numberof_success_per_day);
						$('#lifetimewins').html(Object.life_time_wins);
						$('#life_time_wins').val(Object.life_time_wins);
					});	
				}
			}
		});
	}else{
		window.location="index.html";
	}
});

</script>

<div class="header">
<h1>OMAR GAME CONTROLLER</h1>
	<div style="position:absolute; top:9px; right:50px;z-index:1000;" class="log_out">
		<a href="javascript:void(0);" onclick="logout()" style="color:#fff;">Logout</a>
	</div>
</div>

<center class="div_text_color" id="bodyContent">
<div id="edit_form" class="form_div">
<table id="customers">
<tr>
<td>Win Message English</td>
<td id="winMessage"></td>
</tr>
<tr>
<td>Win Message Arabic</td>
<td id="winMessageArabic"></td>
</tr>
<tr>
<td>Win Logo</td>
<td id="winLogo"><img src="" ></td>
</tr>
<tr>
<td>Image On User Details Form</td>
<td id="RegImage"><img src="" ></td>
</tr>
<tr>
<td>Force To Make User Win After Failure Attempts</td>
<td id="nooffailure_attemts"></td>
</tr>
<tr>
<td>Number Of Chances Per Day</td>
<td id="noofchances_perday"></td>
</tr>
<tr>
<td>Number Of Success Per Day</td>
<td id="noofsuccess_perday"></td>
</tr>
<tr>
<td>Life Time Wins</td>
<td id="lifetimewins"></td>
</tr>
<tr>
</table>
<div class="update_btn">
<input type="button" id="update_data" value="Update" onclick="updateForm(0)" />
</div>
</div>

<!-- FORM  -->

<div id="update_form" style="display:none;" class="form_div">
<form id="form_id" name="form_id" method="POST">
<table  id="customers">
<tr>
<td>Win Message</td>
<td><textarea id="win_message" name="win_message" style="width:100%;"></textarea><span id="errorMessage" style="color:red"></span></td>
</tr>
<tr>
<td>Win Message Arabic</td>
<td><textarea id="win_message_arabic" name="win_message_arabic" style="width:100%;"></textarea><span id="errorMessageArabic" style="color:red"></span></td>
</tr>
<tr>
<td>Win Logo</td>
<td><p id="imglogo"></p><input type="file" id="win_logo" name="win_logo" onchange="storeImage(1)" style="float:left;"><input type="hidden" id="win_logoo" name="win_logoo"><span id="errorWinlogo" style="color:red"></td>
</tr>
<tr>
<td>Image On User Details Form</td>
<td><p id="reglogo"></p><input type="file" id="reg_image" name="reg_image" onchange="storeImage(0)"><input type="hidden" id="reg_imagee" name="reg_imagee"><span id="errorRegimage" style="color:red"></td>
</tr>
<tr>
<td>Force To Make User Win After Failure Attempts</td>
<td><input type="text" id="numberof_failure_attemts" name="numberof_failure_attemts"><span id="errornumberofFaiAttemts" style="color:red"></td>
</tr>
<tr>
<td>Number Of Chances Per Day</td>
<td> <input type="text" id="numberof_chance_per_day" name="numberof_chance_per_day"><span id="errornumberofChancesperday" style="color:red"></td>
</tr>
<tr>
<td>Number Of Success Per Day</td>
<td><input type="text" id="numberof_success_per_day" name="numberof_success_per_day"><span id="errornumberofSuccperday" style="color:red"></td>
</tr>
<tr>
<td>Life Time Wins</td>
<td> <input type="text" id="life_time_wins" name="life_time_wins"><span id="errorlifeTimeWins" style="color:red"> </td>
</tr>
<tr>
</table>
<div class="update_btn">
<input type="button" value="Submit" onclick="updateForm(1)"/>
<input type="button" value="Cancel" onclick="backPage()"/>
<input type="hidden" id="hideenWinId" name="hideenWinId" />
</form>
</div>
</div>

</center>
<span id="load_admin_form" style="display:none"><img src="../images/ajax-load.gif"></span>
<script>
function updateForm(value){
	if(value==0){
		$('#edit_form').hide();
		$('#update_form').show();
	}else{
		var flag=true;
		var winmessage=$('#win_message').val();
		var winmessagearabic=$('#win_message_arabic').val();
		var WinId=$('#hideenWinId').val();
		var winlogo=$('#win_logoo').val();
		var regimage=$('#reg_imagee').val();
		var numberofFaiAttemts=$('#numberof_failure_attemts').val();
		var numberofChancesperday=$('#numberof_chance_per_day').val();
		var numberofSuccperday=$('#numberof_success_per_day').val();
		var lifeTimeWins=$('#life_time_wins').val();
		
		if(winmessage==""){
			$('#errorMessage').html("Required");
			 flag=false;
		}else{
			$('#errorMessage').html("");
		}
		if(winmessagearabic==""){
			$('#errorMessageArabic').html("Required");
			 flag=false;
		}else{
			$('#errorMessageArabic').html("");
		}
		if(numberofFaiAttemts==""){
			$('#errornumberofFaiAttemts').html("Required");
			 flag=false;
		}else if(isNaN(numberofFaiAttemts)){
			$('#errornumberofFaiAttemts').html("Required Numbers Only");
			 flag=false;
		}else{
			$('#errornumberofFaiAttemts').html("");
		}
		if(numberofChancesperday==""){
			$('#errornumberofChancesperday').html("Required");
			 flag=false;
		}else if(isNaN(numberofChancesperday)){
			$('#errornumberofChancesperday').html("Required Numbers Only");
			 flag=false;
		}else{
			$('#errornumberofChancesperday').html("");
		}
		if(numberofSuccperday==""){
			$('#errornumberofSuccperday').html("Required");
			 flag=false;
		}else if(isNaN(numberofSuccperday)){
			$('#errornumberofSuccperday').html("Required Numbers Only");
			 flag=false;
		}else{
			$('#errornumberofSuccperday').html("");
		}
		if(lifeTimeWins==""){
			$('#errorlifeTimeWins').html("Required");
			 flag=false;
		}else if(isNaN(lifeTimeWins)){
			$('#errorlifeTimeWins').html("Required Numbers Only");
			 flag=false;
		}else if(lifeTimeWins <= numberofSuccperday){
			$('#errorlifeTimeWins').html("Lifetime wins is greter than No.of success per day");
			flag=false;
		}else{
			$('#errorlifeTimeWins').html("");
		}
		if(flag==true){
			$('#load_admin_form').show();
			$('#update_form').css('opacity',0.5);
			$.ajax({
				type		:	'PUT',
				url			:  	webServiceUrl+'admin/'+WinId,
				dataType	: 	"json",
				data		:	{win_message:winmessage,numberof_failure_attemts:numberofFaiAttemts,life_time_wins:lifeTimeWins,numberof_success_per_day:numberofSuccperday,numberof_chance_per_day:numberofChancesperday,win_logo:winlogo,reg_image:regimage,win_message_arabic:winmessagearabic},
				success: function(data){
					$('#load_admin_form').hide();
					if(data.value==1){
						window.location="login.html";
					}
				}
			});
		}
	}
}
function storeImage(type){
	if(type==1){
		 var F = $("#win_logo")[0].files;
	}else{
		 var F = $("#reg_image")[0].files;
	}
    if(F && F[0]) for(var i=0; i<F.length; i++) readImage( F[i],type );
}
function readImage(file,type) {

    var reader = new FileReader();
    var image  = new Image();

    reader.readAsDataURL(file);  
    reader.onload = function(_file) {
        image.src    = _file.target.result;
		if(type==1){
			$("#win_logoo").val(image.src);
			$('#imglogo').html('<img src="'+image.src+'" height="42" width="42">');
		}else{
			$("#reg_imagee").val(image.src);
			$('#reglogo').html('<img src="'+image.src+'" height="42" width="42">');
		}
		//alert(image.src);
}
}
function logout(){
	sessionStorage.clear();
	window.location="index.html";
}
function backPage(){
	window.location="login.html";
}
</script>

